//
//  PropertycostsSelectViewController.m
//  WisdomCommunity
//
//  Created by Yahaong on 16/7/28.
//  Copyright © 2016年 zonten. All rights reserved.
//

#import "PropertycostsSelectViewController.h"
#import "WYUserView.h"
#import "UIButton+ButtonStyle.h"
#import "PropertycostsPaymentViewController.h"
#import "YHMarcros.h"

@interface PropertycostsSelectViewController ()
@property(nonatomic, strong)WYUserView *topView;
/** 水费 */
@property(nonatomic, strong)UIButton *waterButton;
/** 电费 */
@property(nonatomic, strong)UIButton *electricButton;
/** 气费 */
@property(nonatomic, strong)UIButton *gasButton;
/** 物业费 */
@property(nonatomic, strong)UIButton *propertyButton;

@property(nonatomic, strong)UITextField *amountTextField;
@property (nonatomic, strong)UIView  *bottomView;
@property (nonatomic, strong)UILabel  *tipsLabel;
@property (nonatomic, strong)UIButton  *nextButton;
@end

@implementation PropertycostsSelectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"物业缴费";
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor ];
    [self.view addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.equalTo(self.view);
        make.height.equalTo(kIphoneSize_Height(120));
    }];
    
    [self.view addSubview:self.waterButton];
    [self.waterButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.bottom).offset(kIphoneSize_Height(20));
        make.leading.equalTo(self.view).offset(20);
        make.width.lessThanOrEqualTo(self.view);
        make.height.equalTo(kIphoneSize_Height(40));
    }];
     [self.view addSubview:self.electricButton];
    [self.electricButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.waterButton.bottom);
        make.leading.trailing.equalTo(self.waterButton);
        make.height.equalTo(self.waterButton);
    }];
    [self.view addSubview:self.gasButton];
    [self.gasButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.electricButton.bottom);
        make.leading.trailing.equalTo(self.waterButton);
        make.height.equalTo(self.waterButton);
    }];
    [self.view addSubview:self.propertyButton];
    [self.propertyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.gasButton.bottom);
        make.leading.trailing.equalTo(self.waterButton);
        make.height.equalTo(self.waterButton);
    }];
    [self.view addSubview:self.amountTextField];
    [self.amountTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.propertyButton.bottom).offset(kIphoneSize_Height(20));
        make.centerX.equalTo(self.view);
        make.width.equalTo(kIphoneSize_Widith(200));
        make.height.equalTo(kIphoneSize_Height(50));
    }];
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.amountTextField.bottom).offset(kIphoneSize_Height(20));
        make.leading.trailing.bottom.equalTo(self.view);
        
    }];
    [self.bottomView addSubview:self.tipsLabel];
    [self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView);
        make.leading.equalTo(self.bottomView).offset(20);
        make.trailing.equalTo(self.bottomView.trailing).offset(-20);
    }];
    [self.bottomView addSubview:self.nextButton];
    [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tipsLabel.bottom).offset(kIphoneSize_Height(80));
        make.leading.equalTo(self.bottomView).offset(10);
        make.trailing.equalTo(self.bottomView.trailing).offset(-10);
        make.height.equalTo(kIphoneSize_Height(40));
        
    }];
  
    
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [self.waterButton layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleLeft imageTitleSpace:20];
    [self.electricButton layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleLeft imageTitleSpace:20];
    [self.gasButton layoutButtonWithEdgeInsetsStyle:ButtonEdgeInsetsStyleLeft imageTitleSpace:20];
    self.propertyButton.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, -20);
    
}

- (void)next
{
    PropertycostsPaymentViewController *propertycostsPayVc = [[PropertycostsPaymentViewController alloc]init];
    [self.navigationController pushViewController:propertycostsPayVc animated:YES];
}
- (void)selectedOrCancel:(UIButton *)button
{
    button.selected = !button.selected;
}
#pragma mark <懒加载>
- (UIView *)topView
{
    if (!_topView) {
        _topView = [[WYUserView alloc]init];
    }
    return _topView;
}

- (UIButton *)waterButton
{
    if (!_waterButton) {
        _waterButton = [[UIButton alloc]init];
        [_waterButton setTitle:@"水费" forState:UIControlStateNormal];
        [_waterButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_waterButton setImage: [UIImage imageNamed:@"property_icon_normal"] forState:UIControlStateNormal];
        [_waterButton setImage:[UIImage imageNamed:@"property_icon_selected"] forState:UIControlStateSelected];
         [_waterButton addTarget:self action:@selector(selectedOrCancel:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _waterButton;
}

- (UIButton *)electricButton
{
    if (!_electricButton) {
        _electricButton = [[UIButton alloc]init];
        [_electricButton setTitle:@"电费" forState:UIControlStateNormal];
        [_electricButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_electricButton setImage: [UIImage imageNamed:@"property_icon_normal"] forState:UIControlStateNormal];
        [_electricButton setImage:[UIImage imageNamed:@"property_icon_selected"] forState:UIControlStateSelected];
        [_electricButton addTarget:self action:@selector(selectedOrCancel:) forControlEvents:UIControlEventTouchUpInside];
        [_electricButton setSelected: YES];
    }
    return _electricButton;
}

- (UIButton *)gasButton
{
    if (!_gasButton) {
        _gasButton = [[UIButton alloc]init];
        [_gasButton setTitle:@"气费" forState:UIControlStateNormal];
        [_gasButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_gasButton setImage: [UIImage imageNamed:@"property_icon_normal"] forState:UIControlStateNormal];
        [_gasButton setImage:[UIImage imageNamed:@"property_icon_selected"] forState:UIControlStateSelected];
         [_gasButton addTarget:self action:@selector(selectedOrCancel:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _gasButton;
}

- (UIButton *)propertyButton
{
    if (!_propertyButton) {
        _propertyButton = [[UIButton alloc]init];
        [_propertyButton setTitle:@"物管费" forState:UIControlStateNormal];
        [_propertyButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_propertyButton setImage: [UIImage imageNamed:@"property_icon_normal"] forState:UIControlStateNormal];
        [_propertyButton setImage:[UIImage imageNamed:@"property_icon_selected"] forState:UIControlStateSelected];
        [_propertyButton setSelected: YES];
        [_propertyButton addTarget:self action:@selector(selectedOrCancel:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _propertyButton;
}

- (UITextField *)amountTextField
{
    if (!_amountTextField) {
        _amountTextField = [[UITextField alloc]init];
        _amountTextField.placeholder = @"请输入缴费金额";
        _amountTextField.backgroundColor = kBgColor;
        _amountTextField.layer.cornerRadius = 5;
        _amountTextField.layer.masksToBounds = YES;

       [_amountTextField setValue: @(NSTextAlignmentCenter)forKeyPath:@"_placeholderLabel.textAlignment"];
        _amountTextField.keyboardType = UIKeyboardTypeDecimalPad;
      
    }
    return _amountTextField;
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]init];
        _bottomView.backgroundColor = kBgColor;
    }
    return _bottomView;
}

- (UILabel *)tipsLabel
{
    if (!_tipsLabel) {
        _tipsLabel = [[UILabel alloc]init];
        _tipsLabel.text = @"本次缴费由物业中心代收，3个工作日内向您所在的小区物业公司转账，最终解释权归中创物业运营中心所有";
        _tipsLabel.numberOfLines = 0;
        _tipsLabel.textColor = RGBColor(102, 102, 102);
    }
    return _tipsLabel;
}
- (UIButton *)nextButton
{
    if (!_nextButton) {
        _nextButton = [[UIButton alloc]init];
        [_nextButton setTitle:@"下一步" forState:UIControlStateNormal];
        _nextButton.backgroundColor = kGlobalRedColor;
        _nextButton.layer.cornerRadius = 5;
        _nextButton.layer.masksToBounds = YES;
        [_nextButton addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextButton;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
@end
